package com.qianduo.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.qianduo.dao.IQianduoAgencyDao;
import com.qianduo.po.QianduoAgency;
import com.qianduo.util.Constants;
import com.qianduo.util.ServiceUtil;
import com.qianduo.vo.QianduoAgencyForm;

import common.page.PageList;
import common.util.ObjectUtil;

@SuppressWarnings("finally")
public class QianduoAgencyServiceImpl extends ServiceUtil{
	private IQianduoAgencyDao qianduoAgencyDao;
	
	
	public IQianduoAgencyDao getQianduoAgencyDao() {
		return qianduoAgencyDao;
	}

	public void setQianduoAgencyDao(IQianduoAgencyDao qianduoAgencyDao) {
		this.qianduoAgencyDao = qianduoAgencyDao;
	}

	public boolean saveOrUpdateAgency(QianduoAgencyForm vo){
		boolean ret		= false;
		try{
			QianduoAgency po	= new QianduoAgency();
			ObjectUtil.copyProperties(po, vo);
			qianduoAgencyDao.saveOrUpdateAgency(po);
			
			ret		= true;
		}catch(Exception e){
			Constants.log.error(className+" saveOrUpdateAgency",e);
		}finally{
			return ret;
		}
	}
	
	public List<QianduoAgencyForm> listAgency(Integer id,String username,Integer type,String name,String phone,Integer isCert,Integer IsBusinessLicense,Integer dutyCert,Integer cityID,String companyName,String productType,Integer times,String createDateStart,String createDateEnd,PageList pageList){
		List<QianduoAgencyForm> retList	= null;
		try{
			List<QianduoAgency> listPO = qianduoAgencyDao.listAgency(id, username, type, name, phone, isCert, IsBusinessLicense, dutyCert, cityID, companyName, productType, times, createDateStart, createDateEnd, pageList);
			if(null != listPO && listPO.size() > 0){
				retList	= new ArrayList<QianduoAgencyForm>();
				for(QianduoAgency po : listPO){
					QianduoAgencyForm vo	= new QianduoAgencyForm();
					ObjectUtil.copyProperties(vo, po);
					
					retList.add(vo);
				}
			}
		}catch(Exception e){
			Constants.log.error(className+" listAgency",e);
		}finally{
			return retList;
		}
	}
	
	public QianduoAgencyForm getAgencyByUser(String username){
		QianduoAgencyForm ret	= null;
		try{
			QianduoAgency po	= qianduoAgencyDao.getAgencyByUser(username);
			if(null != po ){
				ret				= new QianduoAgencyForm();
				ObjectUtil.copyProperties(ret, po);				
			}
		}catch(Exception e){
			Constants.log.error(className+" getAgencyByUser",e);
		}finally{
			return ret;
		}
	}
}
